Skip to content

#1926 - elderberry #2369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

swyxio
Copy link

@swyxio swyxio commented Aug 7, 2025

Likely causes of problems in 6.6.0+

  • Incorrect schema detection in multi-file setups: we weren’t passing --schema when the schema is a directory.
  • Wrong migrations location when using a schema folder: we copied from the parent of schema/ instead of next to schema.prisma.
  • New generator output model confusion: Prisma warns to use an output path and may not write to node_modules in certain setups.
  • prisma.config.ts not being considered could misalign schema/migration paths vs what the CLI uses.
  • package.json.prisma.schema overrides not considered by our logic.
  • typed SQL folder copy based on the wrong base directory.
  • Overly strict assumption that the folder has to be named schema.

Most likely root causes: missing --schema for multi-file schemas, and wrong migrations folder resolution when the main schema lives inside schema/.

Changes implemented in packages/build/src/extensions/prisma.ts

  • Detect schema type robustly:
    • Determine whether options.schema resolves to a file or a directory using statSync.
    • Stop inferring “schema folder” by name; use actual file system info.
  • Always pass --schema explicitly:
    • For directory schemas: --schema=./prisma/schema
    • For single-file schemas: --schema=./prisma/schema.prisma
  • Correct migrations path:
    • Folder schema: copy from <schemaDir>/migrations
    • File schema: copy from <dirname(file)>/migrations
    • Only run migrate deploy if migrations exist, and include the same --schema flag.
  • typed SQL support:
    • Copy from <schemaDir>/sql (folder schema) or <dirname(file)>/sql (file schema), if present.
  • Logging improvements:
    • Added debug logs to confirm resolved paths, whether we’re using a folder or file, copied assets, and the exact Prisma CLI commands being run.

You can review the important edits here:

import { existsSync, statSync } from "node:fs";
// ...
this._schemaIsDirectory = statSync(this._resolvedSchemaPath).isDirectory();
// ...
if (schemaIsDirectory) {
  // Copy all *.prisma to ./prisma/schema and run:
  // node_modules/prisma/build/index.js generate --schema=./prisma/schema
} else {
  // Copy schema.prisma and run:
  // node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma
}
// ...
// Migrations: copy from the correct location based on file vs folder and run:
// migrate deploy --schema=./prisma/schema or ./prisma/schema.prisma

How to validate quickly

  • Deploy/build and check logs:
    • Look for “Using a schema directory” vs “Copying Prisma schema file”.
    • Confirm “Copying Prisma migrations” shows the correct source path.
    • Confirm Prisma commands include the correct --schema flag (directory or file).
  • For typed SQL: verify logs discover and copy files under the expected sql/ dir.

Interim guidance for users on Prisma 6.6.0 (multi-file schema)

  • Put schema.prisma and your other .prisma files together in prisma/schema (or any folder) and pass that folder path to prismaExtension({ schema: "<that-folder>" }), or pass the file path if you use a single-file schema.

  • Ensure migrations sits next to the file that defines datasource (i.e., next to schema.prisma if that’s your main).

  • If you keep a folder schema, prefer configuring your package.json prisma.schema to point at the folder (the extension now passes --schema itself, but the package.json field helps your local tooling).

  • If you’re using the new prisma-client generator, ensure your imports match its output path and bundling setup.

  • I didn’t change our API surface (still prismaExtension({ schema: ... })), but it now handles both files and directories correctly and avoids old assumptions.

  • Next step (optional): Add first-class prisma.config.ts support by copying and rewriting it for the build layer or by parsing it to honor custom schema, migrations.path, and typedSql.path. For now, explicit --schema and correct folder copying should unblock most 6.6.0 setups.

  • If you hit issues in a specific repo, share your prismaExtension call, schema layout, and whether you’re using prisma-client-js or the new prisma-client generator, and we can wire in explicit handling as needed.

  • Updated packages/build/src/extensions/prisma.ts to:

    • Use FS to detect directory vs file for schema
    • Pass --schema in both generate and migrate commands
    • Copy migrations from the correct location (adjacent to main schema)
    • Improve typed SQL copying and logs
  • No linter errors in the file after edits

  • Typecheck for the whole package fails due to cross-package types (unrelated to this change)

Copy link

changeset-bot bot commented Aug 7, 2025

⚠️ No Changeset found

Latest commit: bd44381

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

Walkthrough

The changes update the PrismaExtension to robustly support both single-file and directory-based Prisma schema configurations. The extension now detects whether the provided schema path is a directory or a file using statSync. If a directory is detected, it checks for the presence of a schema.prisma file and logs warnings if missing. During build completion, the logic copies all .prisma files from the directory or the single schema file as appropriate. The Prisma CLI commands are updated to use explicit --schema flags. Handling for typedSql and migrations is also adjusted to account for schema type, with improved error handling and logging throughout.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/build/src/extensions/prisma.ts (2)

78-106: Well-structured schema detection logic!

The implementation correctly:

  • Resolves paths relative to the working directory
  • Provides detailed debug logging for troubleshooting
  • Detects schema type (file vs directory) reliably
  • Warns about missing schema.prisma in multi-file setups

Consider making the warning message at lines 101-103 more actionable by suggesting what the user should do:

-          `PrismaExtension: The provided schema path is a directory (${this._resolvedSchemaPath}) but no schema.prisma was found inside. Ensure your multi-file schema folder contains a schema.prisma with datasource/generator blocks.`
+          `PrismaExtension: The provided schema path is a directory (${this._resolvedSchemaPath}) but no schema.prisma was found inside. Please create a schema.prisma file with datasource/generator blocks in this directory for multi-file schema to work correctly.`

133-133: Simplify boolean conversion

The Boolean() wrapper is unnecessary since _schemaIsDirectory is already typed as boolean.

-    const schemaIsDirectory = Boolean(this._schemaIsDirectory);
+    const schemaIsDirectory = this._schemaIsDirectory ?? false;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da7dc74 and bd44381.

📒 Files selected for processing (1)
  • packages/build/src/extensions/prisma.ts (6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Always prefer using isomorphic code like fetch, ReadableStream, etc. instead of Node.js specific code
For TypeScript, we usually use types over interfaces
Avoid enums
No default exports, use function declarations

Files:

  • packages/build/src/extensions/prisma.ts
🧠 Learnings (12)
📓 Common learnings
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T17:49:24.468Z
Learning: Applies to internal-packages/database/**/*.{ts,tsx} : We use prisma in internal-packages/database for our database interactions using PostgreSQL
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When implementing schema tasks, use `schemaTask` from `trigger.dev/sdk/v3` and validate payloads as shown.
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : Build extensions such as `additionalFiles`, `additionalPackages`, `aptGet`, `emitDecoratorMetadata`, `prismaExtension`, `syncEnvVars`, `puppeteer`, `ffmpeg`, and `esbuildPlugin` must be configured in `trigger.config.ts` as shown.
📚 Learning: applies to internal-packages/database/**/*.{ts,tsx} : we use prisma in internal-packages/database fo...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T17:49:24.468Z
Learning: Applies to internal-packages/database/**/*.{ts,tsx} : We use prisma in internal-packages/database for our database interactions using PostgreSQL

Applied to files:

  • packages/build/src/extensions/prisma.ts
📚 Learning: applies to trigger.config.ts : build extensions such as `additionalfiles`, `additionalpackages`, `ap...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : Build extensions such as `additionalFiles`, `additionalPackages`, `aptGet`, `emitDecoratorMetadata`, `prismaExtension`, `syncEnvVars`, `puppeteer`, `ffmpeg`, and `esbuildPlugin` must be configured in `trigger.config.ts` as shown.

Applied to files:

  • packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when implementing schema tasks, use `schematask` from `...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When implementing schema tasks, use `schemaTask` from `trigger.dev/sdk/v3` and validate payloads as shown.

Applied to files:

  • packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : always generate trigger.dev tasks using the `task` func...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : ALWAYS generate Trigger.dev tasks using the `task` function from `trigger.dev/sdk/v3` and export them as shown in the correct pattern.

Applied to files:

  • packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : you must use `@trigger.dev/sdk/v3` when writing trigger...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : You MUST use `trigger.dev/sdk/v3` when writing Trigger.dev tasks.

Applied to files:

  • packages/build/src/extensions/prisma.ts
📚 Learning: before generating any code for trigger.dev tasks, verify: (1) are you importing from `@trigger.dev/s...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Before generating any code for Trigger.dev tasks, verify: (1) Are you importing from `trigger.dev/sdk/v3`? (2) Have you exported every task? (3) Have you generated any deprecated code patterns?

Applied to files:

  • packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : you must `export` every task, including subtasks, in tr...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : You MUST `export` every task, including subtasks, in Trigger.dev task files.

Applied to files:

  • packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : tasks must be exported, even subtasks in the same file....
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Tasks must be exported, even subtasks in the same file.

Applied to files:

  • packages/build/src/extensions/prisma.ts
📚 Learning: applies to apps/webapp/**/*.{ts,tsx} : when importing from `@trigger.dev/core` in the webapp, never ...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/webapp.mdc:0-0
Timestamp: 2025-07-18T17:49:47.180Z
Learning: Applies to apps/webapp/**/*.{ts,tsx} : When importing from `trigger.dev/core` in the webapp, never import from the root `trigger.dev/core` path; always use one of the subpath exports as defined in the package's package.json.

Applied to files:

  • packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : the `run` function contains your task logic in trigger....
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : The `run` function contains your task logic in Trigger.dev tasks.

Applied to files:

  • packages/build/src/extensions/prisma.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when triggering a task from backend code, use `tasks.tr...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When triggering a task from backend code, use `tasks.trigger`, `tasks.batchTrigger`, or `tasks.triggerAndPoll` as shown in the examples.

Applied to files:

  • packages/build/src/extensions/prisma.ts
🔇 Additional comments (6)
packages/build/src/extensions/prisma.ts (6)

4-4: LGTM!

The addition of statSync is appropriate for detecting whether the schema path is a directory.


59-59: LGTM!

The private property correctly stores the schema type for later use.


148-183: Excellent typedSql handling!

The implementation:

  • Correctly determines the SQL base directory based on schema type
  • Includes proper error handling and existence checks
  • Provides detailed debug logging for troubleshooting
  • Gracefully handles missing SQL directories

185-216: Well-implemented multi-file schema support!

The logic correctly:

  • Identifies and copies all .prisma files from the schema directory
  • Uses the explicit --schema=./prisma/schema flag for Prisma CLI
  • Maintains the schema structure in the build output

217-235: Consistent single-file schema handling!

The implementation properly:

  • Copies the single schema file to the standard location
  • Uses explicit --schema=./prisma/schema.prisma flag for clarity
  • Includes debug logging for troubleshooting

239-267: Robust migrations handling!

The implementation excellently:

  • Checks for migrations directory existence before attempting operations
  • Uses the correct --schema flag based on schema type
  • Provides clear warnings when migrations are expected but missing
  • Prevents errors by skipping migrate deploy when no migrations exist

@ericallam ericallam closed this Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants